// 享元（Flyweight）模式可以说是一种拿来主义模式，是基于一个模板对象来快速生成很多相似对象的方法，是基于共享来快速批量创建相似对象的思想。


 class Person {
    name='';
    age=0;
    address=''
 }

 class PersonFactory{
    personObj = {}
    createPerson(name, age, address){
        let person = null;
        if(this.personObj[address]){
            person = this.personObj[address];
            person.name = name;
            person.age = age;
            console.log("在已经存在的村庄中直接给值:", person);
        }else{
            person = new Person();
            this.personObj[address] = Object.assign({} , person);
            person.name = name;
            person.age = age;
            person.address = address;
            console.log("创建村庄实例, 并且给值", person);
        }
        return person;
    }
 }

 const personFactory = new PersonFactory();
 let person1 = personFactory.createPerson('张三', 20, '田村');
 let person2 = personFactory.createPerson('李四', 21, '田村');

 let person3 = personFactory.createPerson('张五', 21, '王村');
 let person4 = personFactory.createPerson('赵六', 23, '王村');